﻿//准备ExtJS环境
Ext.require
(
    [
        'Ext.tree.*',
        'Ext.grid.*',
        'Ext.data.*',
        'Ext.util.*',
        'Ext.state.*',
        'Ext.form.*'
    ]
);

//处理养护汇总表查看按钮点击事件
function ViewMaintainSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_maintain_summary)
    {
        //创建数据存储对象
        store_maintain_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectMaintainTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_maintain = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_maintain_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 280,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_maintain_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '养护日汇总表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '养护日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkDataType',
                                fieldLabel: '数据类型',
                                columns: 2,
                                vertical: true,
                                items: master_datatypes,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_maintain
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_maintain.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //判断是否为叶子节点
                                                if (node.get('leaf'))
                                                {
                                                    organizations.push(node.get('id'));
                                                }
                                            }
                                        );

                                        //用于保存数据范围
                                        var dataTypes = [];

                                        //获得选中的类型
                                        var checkedTypes = form.down('#chkDataType').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedTypes,
                                            function (item)
                                            {
                                                dataTypes.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'DataTypes': dataTypes,
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/MaintainSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_maintain_summary.show();
}

//处理养护汇总月表查看按钮点击事件
function ViewMaintainMonthSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_maintain_month_summary)
    {
        //创建数据存储对象
        store_maintain_month_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectMaintainTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_maintain_month = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_maintain_month_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 280,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_maintain_month_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '养护月汇总表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '养护日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkDataType',
                                fieldLabel: '数据类型',
                                columns: 2,
                                vertical: true,
                                items: master_datatypes,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_maintain_month
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_maintain_month.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //判断是否为叶子节点
                                                if (node.get('leaf'))
                                                {
                                                    organizations.push(node.get('id'));
                                                }
                                            }
                                        );

                                        //用于保存数据范围
                                        var dataTypes = [];

                                        //获得选中的类型
                                        var checkedTypes = form.down('#chkDataType').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedTypes,
                                            function (item)
                                            {
                                                dataTypes.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'DataTypes': dataTypes,
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/MaintainMonthSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_maintain_month_summary.show();
}

//处理工程人工汇总表查看按钮点击事件
function ViewProjectLabourSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_labour_summary)
    {
        //创建数据存储对象
        store_labour_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_labour = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_labour_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 240,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_labour_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程人工费用统计表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 520,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '施工日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 3,
                                vertical: true,
                                items: master_category,
                                maxHeight: 120
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_labour
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_labour.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectLabourSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_labour_summary.show();
}

//处理工程材料汇总表查看按钮点击事件
function ViewProjectMaterialSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_material_summary)
    {
        //创建数据存储对象
        store_material_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_material = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_material_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 200,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_material_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程材料费用统计表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '施工日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 3,
                                vertical: true,
                                items: master_category,
                                maxHeight: 120
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_material
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_material.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectMaterialSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_material_summary.show();
}

//处理工程机械汇总表查看按钮点击事件
function ViewProjectMachineSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_machine_summary)
    {
        //创建数据存储对象
        store_machine_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_machine = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_machine_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 200,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_machine_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程机械费用统计表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '施工日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 3,
                                vertical: true,
                                items: master_category,
                                maxHeight: 120
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_machine
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_machine.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectMachineSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_machine_summary.show();
}

//处理工程汇总表查看按钮点击事件
function ViewProjectSummaryReport()
{
    //判定窗体是否已经创建
    if (!win_project_summary)
    {
        //创建数据存储对象
        store_project_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_project = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_project_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 150,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_project_summary = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程汇总表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '施工日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 3,
                                vertical: true,
                                items: master_category,
                                maxHeight: 60
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkDataType',
                                fieldLabel: '数据类型',
                                columns: 3,
                                vertical: true,
                                items: master_datatypes,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_project
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_project.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存数据范围
                                        var dataTypes = [];

                                        //获得选中的类型
                                        var checkedTypes = form.down('#chkDataType').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedTypes,
                                            function (item)
                                            {
                                                dataTypes.push(item.inputValue);
                                            }
                                        );


                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'DataTypes': dataTypes,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectSummaryReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_project_summary.show();
}

//处理工程金额控制表点击事件
function ViewProjectCostReport()
{
    //判定窗体是否已经创建
    if (!win_cost)
    {
        //创建数据存储对象
        store_cost_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_cost = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_cost_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 206,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //创建窗体
        win_cost = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程金额控制表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 2,
                                vertical: true,
                                items: master_category,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_cost
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_cost.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectCostReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_cost.show();
}

//处理工程金额控制表点击事件
function ViewProjectPriceWarningReport()
{
    //判定窗体是否已经创建
    if (!win_price)
    {
        //创建数据存储对象
        store_price_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_price = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_price_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 180,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //获得当前日期
        var current = new Date();

        //获得当月第一天
        var firstDate = Ext.Date.getFirstDateOfMonth(current);

        //获得上个月最后一天
        var lastDate = Ext.Date.add(firstDate, Ext.Date.DAY, -1);

        //获得上个月第一天
        firstDate = Ext.Date.getFirstDateOfMonth(lastDate);

        //创建窗体
        win_price = Ext.create
        (
            'Ext.window.Window',
            {
                title: '工程项目价格预警表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'panel',
                                pading: '0 0 0 5',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        value: firstDate,
                                        itemId: 'txtApplicationDate_L',
                                        fieldLabel: '施工日期',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        endDateField: 'txtApplicationDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        value: lastDate,
                                        itemId: 'txtApplicationDate_H',
                                        allowBlank: false,
                                        format: 'Y/m/d',
                                        vtype: 'dateRange',
                                        beginDateField: 'txtApplicationDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 2,
                                vertical: true,
                                items: master_category,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_price
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_price.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue(),
                                            'ApplicationDate_L': form.down('#txtApplicationDate_L').getValue(),
                                            'ApplicationDate_H': form.down('#txtApplicationDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectPriceWarningReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_price.show();
}

//处理工程进度表点击事件
function ViewProjectProgressReport()
{
    //判定窗体是否已经创建
    if (!win_progress)
    {
        //创建数据存储对象
        store_progress_organization = Ext.create
        (
            'Ext.data.TreeStore',
            {
                autoLoad: true,
                remoteFilter: true,
                remoteSort: true,
                model: 'CheckTreeNode',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                folderSort: true,
                clearOnLoad: true,
                proxy:
                {
                    type: 'ajax',
                    url: Common.MakeControllerUrl('Organization', 'SelectProjectTree'),
                    listeners:
                    {
                        exception: function (proxy, response, operation, options)
                        {
                            //处理错误
                            Common.HandleProxyError(proxy, response, operation, options);
                        }
                    }
                }
            }
        );

        //创建组织结构树
        tree_progress = Ext.create
        (
            'Ext.tree.Panel',
            {
                store: store_progress_organization,
                model: 'TreeNodeData',
                defaultRootProperty: 'data',
                defaultRootId: 'root',
                multiSelect: false,
                lines: true,
                folderSort: true,
                clearOnLoad: true,
                rootVisible: false,
                useArrows: false,
                frame: false,
                title: '',
                flex: 1,
                height: 206,
                listeners:
                {
                    //设置两个指头的滚动
                    render: Common.ScrollableRender,
                    checkchange: function (node, checked, options)
                    {
                        //获得父节点
                        var parent = node.parentNode;

                        //判断是否存在父节点
                        while (parent)
                        {
                            //判断是否选中
                            if (checked)
                            {
                                //用于保存是否全部选中
                                var checkedAll = true;

                                //判断所有的子节点是否都已经被选中
                                parent.eachChild
                                (
                                    function (node)
                                    {
                                        checkedAll = node.get('checked') & checkedAll;
                                    }
                                );

                                //判断是否全部选中
                                if (checkedAll)
                                {
                                    //选中父节点
                                    parent.set('checked', checked);
                                }
                                else
                                {
                                    //终止循环
                                    break;
                                }
                            }
                            else
                            {
                                //取消父节点选中
                                parent.set('checked', checked);
                            }

                            //获得父节点
                            parent = parent.parentNode;
                        }

                        //处理所有的子节点
                        node.cascadeBy
                        (
                            function (node)
                            {
                                node.set('checked', checked);
                            }
                        );
                    }
                }
            }
        );

        //创建窗体
        win_progress = Ext.create
        (
            'Ext.window.Window',
            {
                title: '项目进度表',
                maximizable: false,
                maximized: false,
                width: 480,
                height: 480,
                autoScroll: false,
                bodyBorder: false,
                draggable: true,
                isTopContainer: true,
                modal: true,
                resizable: false,
                bodyPadding: 0,
                closeAction: 'hide',
                closable: false,
                layout: 'fit',
                items:
                [
                    {
                        xtype: 'form',
                        frame: false,
                        bodyPadding: 12,
                        bodyStyle: 'background-color:White;margin:0;',
                        bodyBorder: false,
                        border: 0,
                        defaultType: 'textfield',
                        fieldDefaults:
                        {
                            labelAlign: 'left',
                            labelWidth: 72,
                            anchor: '100%'
                        },
                        items:
                        [
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectCode',
                                fieldLabel: '项目编号',
                                allowBlank: true
                            },
                            {
                                xtype: 'textfield',
                                itemId: 'txtProjectName',
                                fieldLabel: '项目名称',
                                emptyText: '',
                                allowBlank: true,
                                maxLength: 80
                            },
                            {
                                xtype: 'panel',
                                layout: 'column',
                                border: 0,
                                items:
                                [
                                    {
                                        columnWidth: 1 / 2,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_L',
                                        fieldLabel: '开工日期',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        endDateField: 'txtStartDate_H'
                                    },
                                    {
                                        xtype: 'displayfield',
                                        value: '　　 ~　　 ',
                                        columnWidth: 1 / 6
                                    },
                                    {
                                        columnWidth: 1 / 3,
                                        xtype: 'datefield',
                                        itemId: 'txtStartDate_H',
                                        format: 'Y/m/d',
                                        allowBlank: true,
                                        vtype: 'dateRange',
                                        beginDateField: 'txtStartDate_L'
                                    }
                                ]
                            },
                            {
                                xtype: 'checkboxgroup',
                                itemId: 'chkCategory',
                                fieldLabel: '项目类别',
                                columns: 2,
                                vertical: true,
                                items: master_category,
                                maxHeight: 60
                            },
                            {
                                xtype: 'panel',
                                border: 0,
                                layout:
                                {
                                    type: 'hbox'
                                },
                                items:
                                [
                                    {
                                        xtype: 'displayfield',
                                        fieldLabel: '所属单位'
                                    },
                                    tree_progress
                                ]
                            }
                        ],
                        buttons:
                        [
                            {
                                text: '确定',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //获得表单对象
                                    var form = this.up('form');

                                    //检查数据是否合法
                                    if (form.getForm().isValid())
                                    {
                                        //隐藏窗体
                                        this.up('window').hide();

                                        //用于保存选中的单位
                                        var organizations = [];

                                        //获得选中的节点
                                        var nodes = tree_progress.getView().getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            nodes,
                                            function (node)
                                            {
                                                //获得编号
                                                var id = node.get('id');

                                                //判断是否为有效编号
                                                if (id != 'root')
                                                {
                                                    organizations.push(id);
                                                }
                                            }
                                        );

                                        //用于保存分类
                                        var categories = [];

                                        //获得选中的分类
                                        var checkedCategoies = form.down('#chkCategory').getChecked();

                                        //循环添加选中的单位
                                        Ext.Array.each
                                        (
                                            checkedCategoies,
                                            function (item)
                                            {
                                                categories.push(item.inputValue);
                                            }
                                        );

                                        //创建查询条件
                                        var condition =
                                        {
                                            'Organizations': organizations,
                                            'Categories': categories,
                                            'ProjectCode': form.down('#txtProjectCode').getValue(),
                                            'ProjectName': form.down('#txtProjectName').getValue(),
                                            'StartDate_L': form.down('#txtStartDate_L').getValue(),
                                            'StartDate_H': form.down('#txtStartDate_H').getValue()
                                        };

                                        //编码
                                        condition = Ext.JSON.encode(condition);

                                        //生成导航地址
                                        var url = HostUrl + '/Report/ProjectProgressReport.aspx?Filter=' + condition;

                                        //执行导航
                                        window.open(url);
                                    }
                                }
                            },
                            {
                                text: '取消',
                                height: 26,
                                margin: 3,
                                handler: function ()
                                {
                                    //隐藏窗体
                                    this.up('window').hide();
                                }
                            }
                        ]
                    }
                ]
            }
        );
    }

    //显示窗体
    win_progress.show();
}

//挂接环境准备完毕事件
Ext.onReady
(
    function ()
    {
        //初始化附加验证类型
        Common.InitAdditionalValidation();
    }
);